package com.madcode.landlordbuddy;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;

import com.madcode.landlordbuddy.dao.Property;
import com.madcode.landlordbuddy.dao.PropertyDAO;


//public class PropertyController implements Controller, ApplicationContextAware{
public class PropertyController extends MultiActionController{
	static Logger logger = Logger.getLogger(PropertyController.class);
	//ApplicationContext applicationContext;

	public ModelAndView add(HttpServletRequest arg0, HttpServletResponse arg1) throws Exception {
//		public ModelAndView handleRequest(HttpServletRequest arg0, HttpServletResponse arg1) throws Exception {
		Property property = new Property();



		PropertyDAO propertyDAO = (PropertyDAO)this.getApplicationContext().getBean("myPropertyDao");
		List<Property> properties = propertyDAO.getProperties();

		logger.info("fetched <" + properties.size() + "> properties");

		// TODO Auto-generated method stub
		return new ModelAndView().addObject("propertyDAO", propertyDAO);
	}

//	public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
//		this.applicationContext = applicationContext;
//
//	}

}
